<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: yangweijie <yangweijiester@gmail.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Admin\Controller;

/**
 * 焦点图管理
 * @author yuanshao
 */
class FocusController extends AdminController {
	function _before_index()
	{
		$typearr = array(1=>'商品分类',2=>'商品详情',3=>'拼团列表',4=>'拼团详情',5=>'商圈列表');
		$this->assign('typearr',$typearr);
		$poslist=M('FocusPos')->select();
		foreach($poslist as $item)
		{
			$posarr[$item['id']]=$item['title'];
		}
		$this->assign('posarr',$posarr);
	}
	function _before_add()
	{
		$typearr = array(1=>'商品分类',2=>'商品详情',3=>'拼团列表',4=>'拼团详情',5=>'商圈列表');
		$this->assign('typearr',$typearr);
		$poslist=M('FocusPos')->select();
		$this->assign('poslist',$poslist);
	}
	function _before_edit()
	{
        $typearr = array(1=>'商品分类',2=>'商品详情',3=>'拼团列表',4=>'拼团详情',5=>'商圈列表');
		$this->assign('typearr',$typearr);
		$poslist=M('FocusPos')->select();
		$this->assign('poslist',$poslist);
	}

	/**
	 * ajax获取可选择的链接值
	 */
	public function getList(){
		$type = I('type');
		if (!$type){
			$list = array();
		}
		switch($type){
			case 1:
				//商品列表（可选择分类）
				$list = M('category')->where('status=1')->order('sort ASC,id DESC')->field('id,title')->select();
				break;
			case 2:
				//商品详情（查询已上架的商品）
				$list = M('product')->where('status=1')->order('id DESC')->field('id,title')->select();
				break;
			case 3:
				//拼团列表（无可选择参数）
				$list = array();
				break;
			case 4:
				//拼团详情（查询未开始和已开始的拼团）
				$list = M('spell')->where('state<3')->order('id DESC')->field('id,title')->select();
				break;
			case 5:
				//商圈列表
				$list = M('BusinessRange')->order('id DESC')->field('id,area_name as title')->select();
				break;
			default:
				$list = array();
				break;
		}
		header('Content-Type: text/plain; charset=utf-8');
		echo json_encode($list);exit;
	}

}
